<html>
<head>
    <title>Function.js Source Code | Sencha Test 1.0.3</title>
    <!--  Generated on  -->
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
    <pre class="editor editor-colors"><div class="line"><a name="line1"><span class="source js"><span class="comment block documentation js"><span class="punctuation definition comment js"><span>/**</span></span></span></span></div><div class="line"><a name="line2"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@class</span></span><span>&nbsp;Function</span></span></span></div><div class="line"><a name="line3"><a name="Function"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line4"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Every&nbsp;function&nbsp;in&nbsp;JavaScript&nbsp;is&nbsp;actually&nbsp;a&nbsp;`Function`&nbsp;object.</span></span></span></div><div class="line"><a name="line5"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line6"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;`Function`&nbsp;objects&nbsp;created&nbsp;with&nbsp;the&nbsp;`Function`&nbsp;constructor&nbsp;are&nbsp;parsed&nbsp;when&nbsp;the</span></span></span></div><div class="line"><a name="line7"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;function&nbsp;is&nbsp;created.&nbsp;This&nbsp;is&nbsp;less&nbsp;efficient&nbsp;than&nbsp;declaring&nbsp;a&nbsp;function&nbsp;and</span></span></span></div><div class="line"><a name="line8"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;calling&nbsp;it&nbsp;within&nbsp;your&nbsp;code,&nbsp;because&nbsp;functions&nbsp;declared&nbsp;with&nbsp;the&nbsp;function</span></span></span></div><div class="line"><a name="line9"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;statement&nbsp;are&nbsp;parsed&nbsp;with&nbsp;the&nbsp;rest&nbsp;of&nbsp;the&nbsp;code.</span></span></span></div><div class="line"><a name="line10"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line11"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;All&nbsp;arguments&nbsp;passed&nbsp;to&nbsp;the&nbsp;function&nbsp;are&nbsp;treated&nbsp;as&nbsp;the&nbsp;names&nbsp;of&nbsp;the</span></span></span></div><div class="line"><a name="line12"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;identifiers&nbsp;of&nbsp;the&nbsp;parameters&nbsp;in&nbsp;the&nbsp;function&nbsp;to&nbsp;be&nbsp;created,&nbsp;in&nbsp;the&nbsp;order&nbsp;in</span></span></span></div><div class="line"><a name="line13"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;which&nbsp;they&nbsp;are&nbsp;passed.</span></span></span></div><div class="line"><a name="line14"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line15"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Invoking&nbsp;the&nbsp;`Function`&nbsp;constructor&nbsp;as&nbsp;a&nbsp;function&nbsp;(without&nbsp;using&nbsp;the&nbsp;`new`</span></span></span></div><div class="line"><a name="line16"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;operator)&nbsp;has&nbsp;the&nbsp;same&nbsp;effect&nbsp;as&nbsp;invoking&nbsp;it&nbsp;as&nbsp;a&nbsp;constructor.</span></span></span></div><div class="line"><a name="line17"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line18"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;#&nbsp;Specifying&nbsp;arguments&nbsp;with&nbsp;the&nbsp;`Function`&nbsp;constructor</span></span></span></div><div class="line"><a name="line19"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line20"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;The&nbsp;following&nbsp;code&nbsp;creates&nbsp;a&nbsp;`Function`&nbsp;object&nbsp;that&nbsp;takes&nbsp;two&nbsp;arguments.</span></span></span></div><div class="line"><a name="line21"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line22"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Example&nbsp;can&nbsp;be&nbsp;run&nbsp;directly&nbsp;in&nbsp;your&nbsp;JavaScript&nbsp;console</span></span></span></div><div class="line"><a name="line23"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line24"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Create&nbsp;a&nbsp;function&nbsp;that&nbsp;takes&nbsp;two&nbsp;arguments&nbsp;and&nbsp;returns&nbsp;the&nbsp;sum&nbsp;of&nbsp;those</span></span></span></div><div class="line"><a name="line25"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arguments</span></span></span></div><div class="line"><a name="line26"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;adder&nbsp;=&nbsp;new&nbsp;Function(&quot;a&quot;,&nbsp;&quot;b&quot;,&nbsp;&quot;return&nbsp;a&nbsp;+&nbsp;b&quot;);</span></span></span></div><div class="line"><a name="line27"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line28"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Call&nbsp;the&nbsp;function</span></span></span></div><div class="line"><a name="line29"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adder(2,&nbsp;6);</span></span></span></div><div class="line"><a name="line30"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&gt;&nbsp;8</span></span></span></div><div class="line"><a name="line31"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line32"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;The&nbsp;arguments&nbsp;&quot;a&quot;&nbsp;and&nbsp;&quot;b&quot;&nbsp;are&nbsp;formal&nbsp;argument&nbsp;names&nbsp;that&nbsp;are&nbsp;used&nbsp;in&nbsp;the</span></span></span></div><div class="line"><a name="line33"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;function&nbsp;body,&nbsp;&quot;return&nbsp;a&nbsp;+&nbsp;b&quot;.</span></span></span></div><div class="line"><a name="line34"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line35"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&lt;div&nbsp;class=&quot;notice&quot;&gt;</span></span></span></div><div class="line"><a name="line36"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Documentation&nbsp;for&nbsp;this&nbsp;class&nbsp;comes&nbsp;from&nbsp;[MDN](</span><span class="markup underline link https hyperlink"><span>https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function</span></span><span>)</span></span></span></div><div class="line"><a name="line37"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;and&nbsp;is&nbsp;available&nbsp;under&nbsp;[Creative&nbsp;Commons:&nbsp;Attribution-Sharealike&nbsp;license](</span><span class="markup underline link http hyperlink"><span>http://creativecommons.org/licenses/by-sa/2.0/</span></span><span>).</span></span></span></div><div class="line"><a name="line38"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&lt;/div&gt;</span></span></span></div><div class="line"><a name="line39"><span class="source js"><span class="comment block documentation js"><span>&nbsp;</span><span class="punctuation definition comment js"><span>*/</span></span></span></span></div><div class="line"><a name="line40"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line41"><span class="source js"><span class="comment block documentation js"><span class="punctuation definition comment js"><span>/**</span></span></span></span></div><div class="line"><a name="line42"><a name="Function-method-constructor"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@method</span></span><span>&nbsp;constructor</span></span></span></div><div class="line"><a name="line43"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Creates&nbsp;new&nbsp;Function&nbsp;object.</span></span></span></div><div class="line"><a name="line44"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line45"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;{String...}&nbsp;args</span></span></span></div><div class="line"><a name="line46"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Names&nbsp;to&nbsp;be&nbsp;used&nbsp;by&nbsp;the&nbsp;function&nbsp;as&nbsp;formal&nbsp;argument&nbsp;names.&nbsp;Each&nbsp;must&nbsp;be&nbsp;a</span></span></span></div><div class="line"><a name="line47"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;string&nbsp;that&nbsp;corresponds&nbsp;to&nbsp;a&nbsp;valid&nbsp;JavaScript&nbsp;identifier&nbsp;or&nbsp;a&nbsp;list&nbsp;of&nbsp;such</span></span></span></div><div class="line"><a name="line48"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;strings&nbsp;separated&nbsp;with&nbsp;a&nbsp;comma;&nbsp;for&nbsp;example&nbsp;&quot;`x`&quot;,&nbsp;&quot;`theValue`&quot;,&nbsp;or&nbsp;&quot;`a,b`&quot;.</span></span></span></div><div class="line"><a name="line49"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{String}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>functionBody</span></span><span>&nbsp;</span></span></span></span></div><div class="line"><a name="line50"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;A&nbsp;string&nbsp;containing&nbsp;the&nbsp;JavaScript&nbsp;statements&nbsp;comprising&nbsp;the&nbsp;function</span></span></span></div><div class="line"><a name="line51"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;definition.</span></span></span></div><div class="line"><a name="line52"><span class="source js"><span class="comment block documentation js"><span>&nbsp;</span><span class="punctuation definition comment js"><span>*/</span></span></span></span></div><div class="line"><a name="line53"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line54"><span class="source js"><span class="comment line double-slash js"><span class="punctuation definition comment js"><span>//</span></span><span>&nbsp;Properties</span><span>&nbsp;</span></span></span></div><div class="line"><a name="line55"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line56"><span class="source js"><span class="comment block documentation js"><span class="punctuation definition comment js"><span>/**</span></span></span></span></div><div class="line"><a name="line57"><a name="Function-property-length"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@property</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Number}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>length</span></span><span>&nbsp;</span></span></span></span></div><div class="line"><a name="line58"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Specifies&nbsp;the&nbsp;number&nbsp;of&nbsp;arguments&nbsp;expected&nbsp;by&nbsp;the&nbsp;function.</span></span></span></div><div class="line"><a name="line59"><span class="source js"><span class="comment block documentation js"><span>&nbsp;</span><span class="punctuation definition comment js"><span>*/</span></span></span></span></div><div class="line"><a name="line60"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line61"><span class="source js"><span class="comment line double-slash js"><span class="punctuation definition comment js"><span>//</span></span><span>Methods</span><span>&nbsp;</span></span></span></div><div class="line"><a name="line62"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line63"><span class="source js"><span class="comment block documentation js"><span class="punctuation definition comment js"><span>/**</span></span></span></span></div><div class="line"><a name="line64"><a name="Function-method-apply"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@method</span></span><span>&nbsp;apply</span></span></span></div><div class="line"><a name="line65"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Applies&nbsp;the&nbsp;method&nbsp;of&nbsp;another&nbsp;object&nbsp;in&nbsp;the&nbsp;context&nbsp;of&nbsp;a&nbsp;different&nbsp;object&nbsp;(the</span></span></span></div><div class="line"><a name="line66"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;calling&nbsp;object);&nbsp;arguments&nbsp;can&nbsp;be&nbsp;passed&nbsp;as&nbsp;an&nbsp;Array&nbsp;object.</span></span></span></div><div class="line"><a name="line67"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line68"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;You&nbsp;can&nbsp;assign&nbsp;a&nbsp;different&nbsp;this&nbsp;object&nbsp;when&nbsp;calling&nbsp;an&nbsp;existing&nbsp;function.&nbsp;`this`&nbsp;refers&nbsp;to&nbsp;the</span></span></span></div><div class="line"><a name="line69"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;current&nbsp;object,&nbsp;the&nbsp;calling&nbsp;object.&nbsp;With&nbsp;`apply`,&nbsp;you&nbsp;can&nbsp;write&nbsp;a&nbsp;method&nbsp;once&nbsp;and&nbsp;then&nbsp;inherit&nbsp;it</span></span></span></div><div class="line"><a name="line70"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;in&nbsp;another&nbsp;object,&nbsp;without&nbsp;having&nbsp;to&nbsp;rewrite&nbsp;the&nbsp;method&nbsp;for&nbsp;the&nbsp;new&nbsp;object.</span></span></span></div><div class="line"><a name="line71"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line72"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;`apply`&nbsp;is&nbsp;very&nbsp;similar&nbsp;to&nbsp;call,&nbsp;except&nbsp;for&nbsp;the&nbsp;type&nbsp;of&nbsp;arguments&nbsp;it&nbsp;supports.&nbsp;You&nbsp;can&nbsp;use&nbsp;an</span></span></span></div><div class="line"><a name="line73"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;arguments&nbsp;array&nbsp;instead&nbsp;of&nbsp;a&nbsp;named&nbsp;set&nbsp;of&nbsp;parameters.&nbsp;With&nbsp;apply,&nbsp;you&nbsp;can&nbsp;use&nbsp;an&nbsp;array&nbsp;literal,&nbsp;for</span></span></span></div><div class="line"><a name="line74"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;example,&nbsp;`fun.apply(this,&nbsp;[&#39;eat&#39;,&nbsp;&#39;bananas&#39;])`,&nbsp;or&nbsp;an&nbsp;Array&nbsp;object,&nbsp;for&nbsp;example,&nbsp;`fun.apply(this,</span></span></span></div><div class="line"><a name="line75"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;new&nbsp;Array(&#39;eat&#39;,&nbsp;&#39;bananas&#39;))`.</span></span></span></div><div class="line"><a name="line76"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line77"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;You&nbsp;can&nbsp;also&nbsp;use&nbsp;arguments&nbsp;for&nbsp;the&nbsp;`argsArray`&nbsp;parameter.&nbsp;`arguments`&nbsp;is&nbsp;a&nbsp;local&nbsp;variable&nbsp;of&nbsp;a</span></span></span></div><div class="line"><a name="line78"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;function.&nbsp;It&nbsp;can&nbsp;be&nbsp;used&nbsp;for&nbsp;all&nbsp;unspecified&nbsp;arguments&nbsp;of&nbsp;the&nbsp;called&nbsp;object.&nbsp;Thus,&nbsp;you&nbsp;do&nbsp;not&nbsp;have</span></span></span></div><div class="line"><a name="line79"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;to&nbsp;know&nbsp;the&nbsp;arguments&nbsp;of&nbsp;the&nbsp;called&nbsp;object&nbsp;when&nbsp;you&nbsp;use&nbsp;the&nbsp;`apply`&nbsp;method.&nbsp;You&nbsp;can&nbsp;use&nbsp;arguments</span></span></span></div><div class="line"><a name="line80"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;to&nbsp;pass&nbsp;all&nbsp;the&nbsp;arguments&nbsp;to&nbsp;the&nbsp;called&nbsp;object.&nbsp;The&nbsp;called&nbsp;object&nbsp;is&nbsp;then&nbsp;responsible&nbsp;for&nbsp;handling</span></span></span></div><div class="line"><a name="line81"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;arguments.</span></span></span></div><div class="line"><a name="line82"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line83"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Since&nbsp;ECMAScript&nbsp;5th&nbsp;Edition&nbsp;you&nbsp;can&nbsp;also&nbsp;use&nbsp;any&nbsp;kind&nbsp;of&nbsp;object&nbsp;which&nbsp;is&nbsp;array&nbsp;like,&nbsp;so&nbsp;in</span></span></span></div><div class="line"><a name="line84"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;practice&nbsp;this&nbsp;means&nbsp;it&#39;s&nbsp;going&nbsp;to&nbsp;have&nbsp;a&nbsp;property&nbsp;length&nbsp;and&nbsp;integer&nbsp;properties&nbsp;in&nbsp;the&nbsp;range</span></span></span></div><div class="line"><a name="line85"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;`[0...length)`.&nbsp;As&nbsp;an&nbsp;example&nbsp;you&nbsp;can&nbsp;now&nbsp;use&nbsp;a&nbsp;NodeList&nbsp;or&nbsp;a&nbsp;own&nbsp;custom&nbsp;object&nbsp;like&nbsp;`{&#39;length&#39;:&nbsp;2,</span></span></span></div><div class="line"><a name="line86"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&#39;0&#39;:&nbsp;&#39;eat&#39;,&nbsp;&#39;1&#39;:&nbsp;&#39;bananas&#39;}`.</span></span></span></div><div class="line"><a name="line87"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line88"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;You&nbsp;can&nbsp;use&nbsp;`apply`&nbsp;to&nbsp;chain&nbsp;constructors&nbsp;for&nbsp;an&nbsp;object,&nbsp;similar&nbsp;to&nbsp;Java.&nbsp;In&nbsp;the&nbsp;following&nbsp;example,</span></span></span></div><div class="line"><a name="line89"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;constructor&nbsp;for&nbsp;the&nbsp;`Product`&nbsp;object&nbsp;is&nbsp;defined&nbsp;with&nbsp;two&nbsp;parameters,&nbsp;`name`&nbsp;and&nbsp;`value`.&nbsp;Two</span></span></span></div><div class="line"><a name="line90"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;other&nbsp;functions&nbsp;`Food`&nbsp;and&nbsp;`Toy`&nbsp;invoke&nbsp;`Product`&nbsp;passing&nbsp;`this`&nbsp;and&nbsp;`arguments`.&nbsp;`Product`</span></span></span></div><div class="line"><a name="line91"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;initializes&nbsp;the&nbsp;properties&nbsp;`name`&nbsp;and&nbsp;`price`,&nbsp;both&nbsp;specialized&nbsp;functions&nbsp;define&nbsp;the&nbsp;category.&nbsp;In</span></span></span></div><div class="line"><a name="line92"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;this&nbsp;example,&nbsp;the&nbsp;`arguments`&nbsp;object&nbsp;is&nbsp;fully&nbsp;passed&nbsp;to&nbsp;the&nbsp;product&nbsp;constructor&nbsp;and&nbsp;corresponds&nbsp;to</span></span></span></div><div class="line"><a name="line93"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;two&nbsp;defined&nbsp;parameters.</span></span></span></div><div class="line"><a name="line94"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line95"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;Product(name,&nbsp;price)&nbsp;{</span></span></span></div><div class="line"><a name="line96"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.name&nbsp;=&nbsp;name;</span></span></span></div><div class="line"><a name="line97"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.price&nbsp;=&nbsp;price;</span></span></span></div><div class="line"><a name="line98"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line99"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(price&nbsp;&lt;&nbsp;0)</span></span></span></div><div class="line"><a name="line100"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;RangeError(&#39;Cannot&nbsp;create&nbsp;product&nbsp;&quot;&#39;&nbsp;+&nbsp;name&nbsp;+&nbsp;&#39;&quot;&nbsp;with&nbsp;a&nbsp;negative&nbsp;price&#39;);</span></span></span></div><div class="line"><a name="line101"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this;</span></span></span></div><div class="line"><a name="line102"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line103"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line104"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;Food(name,&nbsp;price)&nbsp;{</span></span></span></div><div class="line"><a name="line105"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.apply(this,&nbsp;arguments);</span></span></span></div><div class="line"><a name="line106"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.category&nbsp;=&nbsp;&#39;food&#39;;</span></span></span></div><div class="line"><a name="line107"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line108"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Food.prototype&nbsp;=&nbsp;new&nbsp;Product();</span></span></span></div><div class="line"><a name="line109"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line110"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;Toy(name,&nbsp;price)&nbsp;{</span></span></span></div><div class="line"><a name="line111"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.apply(this,&nbsp;arguments);</span></span></span></div><div class="line"><a name="line112"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.category&nbsp;=&nbsp;&#39;toy&#39;;</span></span></span></div><div class="line"><a name="line113"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line114"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toy.prototype&nbsp;=&nbsp;new&nbsp;Product();</span></span></span></div><div class="line"><a name="line115"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line116"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;cheese&nbsp;=&nbsp;new&nbsp;Food(&#39;feta&#39;,&nbsp;5);</span></span></span></div><div class="line"><a name="line117"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;fun&nbsp;=&nbsp;new&nbsp;Toy(&#39;robot&#39;,&nbsp;40);</span></span></span></div><div class="line"><a name="line118"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line119"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Clever&nbsp;usage&nbsp;of&nbsp;`apply`&nbsp;allows&nbsp;you&nbsp;to&nbsp;use&nbsp;built-ins&nbsp;functions&nbsp;for&nbsp;some&nbsp;tasks&nbsp;that&nbsp;otherwise</span></span></span></div><div class="line"><a name="line120"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;probably&nbsp;would&nbsp;have&nbsp;been&nbsp;written&nbsp;by&nbsp;looping&nbsp;over&nbsp;the&nbsp;array&nbsp;values.&nbsp;As&nbsp;an&nbsp;example&nbsp;here&nbsp;we&nbsp;are&nbsp;going</span></span></span></div><div class="line"><a name="line121"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;to&nbsp;use&nbsp;Math.max/Math.min&nbsp;to&nbsp;find&nbsp;out&nbsp;the&nbsp;maximum/minimum&nbsp;value&nbsp;in&nbsp;an&nbsp;array.</span></span></span></div><div class="line"><a name="line122"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line123"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//min/max&nbsp;number&nbsp;in&nbsp;an&nbsp;array</span></span></span></div><div class="line"><a name="line124"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;numbers&nbsp;=&nbsp;[5,&nbsp;6,&nbsp;2,&nbsp;3,&nbsp;7];</span></span></span></div><div class="line"><a name="line125"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line126"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//using&nbsp;Math.min/Math.max&nbsp;apply</span></span></span></div><div class="line"><a name="line127"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;max&nbsp;=&nbsp;Math.max.apply(null,&nbsp;numbers);&nbsp;//&nbsp;This&nbsp;about&nbsp;equal&nbsp;to&nbsp;Math.max(numbers[0],&nbsp;...)&nbsp;or</span></span></span></div><div class="line"><a name="line128"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Math.max(5,&nbsp;6,&nbsp;..)</span></span></span></div><div class="line"><a name="line129"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;min&nbsp;=&nbsp;Math.min.apply(null,&nbsp;numbers);</span></span></span></div><div class="line"><a name="line130"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line131"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//vs.&nbsp;simple&nbsp;loop&nbsp;based&nbsp;algorithm</span></span></span></div><div class="line"><a name="line132"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max&nbsp;=&nbsp;-Infinity,&nbsp;min&nbsp;=&nbsp;+Infinity;</span></span></span></div><div class="line"><a name="line133"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line134"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;numbers.length;&nbsp;i++)&nbsp;{</span></span></span></div><div class="line"><a name="line135"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(numbers[i]&nbsp;&gt;&nbsp;max)</span></span></span></div><div class="line"><a name="line136"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max&nbsp;=&nbsp;numbers[i];</span></span></span></div><div class="line"><a name="line137"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(numbers[i]&nbsp;&lt;&nbsp;min)</span></span></span></div><div class="line"><a name="line138"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min&nbsp;=&nbsp;numbers[i];</span></span></span></div><div class="line"><a name="line139"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line140"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line141"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;But&nbsp;beware:&nbsp;in&nbsp;using&nbsp;`apply`&nbsp;this&nbsp;way,&nbsp;you&nbsp;run&nbsp;the&nbsp;risk&nbsp;of&nbsp;exceeding&nbsp;the&nbsp;JavaScript&nbsp;engine&#39;s</span></span></span></div><div class="line"><a name="line142"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;argument&nbsp;length&nbsp;limit.&nbsp;The&nbsp;consequences&nbsp;of&nbsp;applying&nbsp;a&nbsp;function&nbsp;with&nbsp;too&nbsp;many&nbsp;arguments&nbsp;(think&nbsp;more</span></span></span></div><div class="line"><a name="line143"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;than&nbsp;tens&nbsp;of&nbsp;thousands&nbsp;of&nbsp;arguments)&nbsp;vary&nbsp;across&nbsp;engines,&nbsp;because&nbsp;the&nbsp;limit&nbsp;(indeed&nbsp;even&nbsp;the&nbsp;nature</span></span></span></div><div class="line"><a name="line144"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;of&nbsp;any&nbsp;excessively-large-stack&nbsp;behavior)&nbsp;is&nbsp;unspecified.&nbsp;Some&nbsp;engines&nbsp;will&nbsp;throw&nbsp;an&nbsp;exception.&nbsp;More</span></span></span></div><div class="line"><a name="line145"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;perniciously,&nbsp;others&nbsp;will&nbsp;arbitrarily&nbsp;limit&nbsp;the&nbsp;number&nbsp;of&nbsp;arguments&nbsp;actually&nbsp;passed&nbsp;to&nbsp;the&nbsp;applied</span></span></span></div><div class="line"><a name="line146"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;function.&nbsp;(To&nbsp;illustrate&nbsp;this&nbsp;latter&nbsp;case:&nbsp;if&nbsp;such&nbsp;an&nbsp;engine&nbsp;had&nbsp;a&nbsp;limit&nbsp;of&nbsp;four&nbsp;arguments&nbsp;[actual</span></span></span></div><div class="line"><a name="line147"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;limits&nbsp;are&nbsp;of&nbsp;course&nbsp;significantly&nbsp;higher],&nbsp;it&nbsp;would&nbsp;be&nbsp;as&nbsp;if&nbsp;the&nbsp;arguments&nbsp;5,&nbsp;6,&nbsp;2,&nbsp;3&nbsp;had&nbsp;been</span></span></span></div><div class="line"><a name="line148"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;passed&nbsp;to&nbsp;apply&nbsp;in&nbsp;the&nbsp;examples&nbsp;above,&nbsp;rather&nbsp;than&nbsp;the&nbsp;full&nbsp;array.)&nbsp;&nbsp;If&nbsp;your&nbsp;value&nbsp;array&nbsp;might&nbsp;grow</span></span></span></div><div class="line"><a name="line149"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;into&nbsp;the&nbsp;tens&nbsp;of&nbsp;thousands,&nbsp;use&nbsp;a&nbsp;hybrid&nbsp;strategy:&nbsp;apply&nbsp;your&nbsp;function&nbsp;to&nbsp;chunks&nbsp;of&nbsp;the&nbsp;array&nbsp;at&nbsp;a</span></span></span></div><div class="line"><a name="line150"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;time:</span></span></span></div><div class="line"><a name="line151"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line152"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;minOfArray(arr)</span></span></span></div><div class="line"><a name="line153"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span></span></span></div><div class="line"><a name="line154"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;min&nbsp;=&nbsp;Infinity;</span></span></span></div><div class="line"><a name="line155"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;QUANTUM&nbsp;=&nbsp;32768;</span></span></span></div><div class="line"><a name="line156"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;i&nbsp;=&nbsp;0,&nbsp;len&nbsp;=&nbsp;arr.length;&nbsp;i&nbsp;&lt;&nbsp;len;&nbsp;i&nbsp;+=&nbsp;QUANTUM)</span></span></span></div><div class="line"><a name="line157"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span></span></span></div><div class="line"><a name="line158"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;submin&nbsp;=&nbsp;Math.min.apply(null,&nbsp;numbers.slice(i,&nbsp;Math.min(i&nbsp;+&nbsp;QUANTUM,&nbsp;len)));</span></span></span></div><div class="line"><a name="line159"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min&nbsp;=&nbsp;Math.min(submin,&nbsp;min);</span></span></span></div><div class="line"><a name="line160"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line161"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;min;</span></span></span></div><div class="line"><a name="line162"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line163"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line164"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;min&nbsp;=&nbsp;minOfArray([5,&nbsp;6,&nbsp;2,&nbsp;3,&nbsp;7]);</span></span></span></div><div class="line"><a name="line165"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line166"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Object}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>thisArg</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>The&nbsp;value&nbsp;of&nbsp;this&nbsp;provided&nbsp;for&nbsp;the&nbsp;call&nbsp;to&nbsp;fun.&nbsp;Note&nbsp;that&nbsp;this&nbsp;may&nbsp;not&nbsp;be</span></span></span></span></span></div><div class="line"><a name="line167"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;actual&nbsp;value&nbsp;seen&nbsp;by&nbsp;the&nbsp;method:&nbsp;if&nbsp;the&nbsp;method&nbsp;is&nbsp;a&nbsp;function&nbsp;in&nbsp;non-strict&nbsp;mode&nbsp;code,&nbsp;null&nbsp;and</span></span></span></div><div class="line"><a name="line168"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;undefined&nbsp;will&nbsp;be&nbsp;replaced&nbsp;with&nbsp;the&nbsp;global&nbsp;object,&nbsp;and&nbsp;primitive&nbsp;values&nbsp;will&nbsp;be&nbsp;boxed.</span></span></span></div><div class="line"><a name="line169"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Array}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>argsArray</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>An&nbsp;array&nbsp;like&nbsp;object,&nbsp;specifying&nbsp;the&nbsp;arguments&nbsp;with&nbsp;which&nbsp;fun&nbsp;should&nbsp;be</span></span></span></span></span></div><div class="line"><a name="line170"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;called,&nbsp;or&nbsp;null&nbsp;or&nbsp;undefined&nbsp;if&nbsp;no&nbsp;arguments&nbsp;should&nbsp;be&nbsp;provided&nbsp;to&nbsp;the&nbsp;function.</span></span></span></div><div class="line"><a name="line171"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@return</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Object}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>Returns</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>what&nbsp;the&nbsp;function&nbsp;returns.</span></span></span></span></span></div><div class="line"><a name="line172"><span class="source js"><span class="comment block documentation js"><span>&nbsp;</span><span class="punctuation definition comment js"><span>*/</span></span></span></span></div><div class="line"><a name="line173"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line174"><span class="source js"><span class="comment block documentation js"><span class="punctuation definition comment js"><span>/**</span></span></span></span></div><div class="line"><a name="line175"><a name="Function-method-call"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@method</span></span><span>&nbsp;call</span></span></span></div><div class="line"><a name="line176"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Calls&nbsp;(executes)&nbsp;a&nbsp;method&nbsp;of&nbsp;another&nbsp;object&nbsp;in&nbsp;the&nbsp;context&nbsp;of&nbsp;a&nbsp;different</span></span></span></div><div class="line"><a name="line177"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;object&nbsp;(the&nbsp;calling&nbsp;object);&nbsp;arguments&nbsp;can&nbsp;be&nbsp;passed&nbsp;as&nbsp;they&nbsp;are.</span></span></span></div><div class="line"><a name="line178"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line179"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;You&nbsp;can&nbsp;assign&nbsp;a&nbsp;different&nbsp;this&nbsp;object&nbsp;when&nbsp;calling&nbsp;an&nbsp;existing&nbsp;function.&nbsp;`this`&nbsp;refers&nbsp;to&nbsp;the</span></span></span></div><div class="line"><a name="line180"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;current&nbsp;object,&nbsp;the&nbsp;calling&nbsp;object.</span></span></span></div><div class="line"><a name="line181"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line182"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;With&nbsp;`call`,&nbsp;you&nbsp;can&nbsp;write&nbsp;a&nbsp;method&nbsp;once&nbsp;and&nbsp;then&nbsp;inherit&nbsp;it&nbsp;in&nbsp;another&nbsp;object,&nbsp;without&nbsp;having&nbsp;to</span></span></span></div><div class="line"><a name="line183"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;rewrite&nbsp;the&nbsp;method&nbsp;for&nbsp;the&nbsp;new&nbsp;object.</span></span></span></div><div class="line"><a name="line184"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line185"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;You&nbsp;can&nbsp;use&nbsp;call&nbsp;to&nbsp;chain&nbsp;constructors&nbsp;for&nbsp;an&nbsp;object,&nbsp;similar&nbsp;to&nbsp;Java.&nbsp;In&nbsp;the&nbsp;following&nbsp;example,</span></span></span></div><div class="line"><a name="line186"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;constructor&nbsp;for&nbsp;the&nbsp;product&nbsp;object&nbsp;is&nbsp;defined&nbsp;with&nbsp;two&nbsp;parameters,&nbsp;name&nbsp;and&nbsp;value.&nbsp;Another</span></span></span></div><div class="line"><a name="line187"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;object,&nbsp;`prod_dept`,&nbsp;initializes&nbsp;its&nbsp;unique&nbsp;variable&nbsp;(`dept`)&nbsp;and&nbsp;calls&nbsp;the&nbsp;constructor&nbsp;for</span></span></span></div><div class="line"><a name="line188"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;`product`&nbsp;in&nbsp;its&nbsp;constructor&nbsp;to&nbsp;initialize&nbsp;the&nbsp;other&nbsp;variables.</span></span></span></div><div class="line"><a name="line189"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line190"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;Product(name,&nbsp;price)&nbsp;{</span></span></span></div><div class="line"><a name="line191"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.name&nbsp;=&nbsp;name;</span></span></span></div><div class="line"><a name="line192"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.price&nbsp;=&nbsp;price;</span></span></span></div><div class="line"><a name="line193"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line194"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(price&nbsp;&lt;&nbsp;0)</span></span></span></div><div class="line"><a name="line195"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;RangeError(&#39;Cannot&nbsp;create&nbsp;product&nbsp;&quot;&#39;&nbsp;+&nbsp;name&nbsp;+&nbsp;&#39;&quot;&nbsp;with&nbsp;a&nbsp;negative&nbsp;price&#39;);</span></span></span></div><div class="line"><a name="line196"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this;</span></span></span></div><div class="line"><a name="line197"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line198"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line199"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;Food(name,&nbsp;price)&nbsp;{</span></span></span></div><div class="line"><a name="line200"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.call(this,&nbsp;name,&nbsp;price);</span></span></span></div><div class="line"><a name="line201"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.category&nbsp;=&nbsp;&#39;food&#39;;</span></span></span></div><div class="line"><a name="line202"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line203"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Food.prototype&nbsp;=&nbsp;new&nbsp;Product();</span></span></span></div><div class="line"><a name="line204"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line205"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;Toy(name,&nbsp;price)&nbsp;{</span></span></span></div><div class="line"><a name="line206"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.call(this,&nbsp;name,&nbsp;price);</span></span></span></div><div class="line"><a name="line207"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.category&nbsp;=&nbsp;&#39;toy&#39;;</span></span></span></div><div class="line"><a name="line208"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line209"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toy.prototype&nbsp;=&nbsp;new&nbsp;Product();</span></span></span></div><div class="line"><a name="line210"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line211"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;cheese&nbsp;=&nbsp;new&nbsp;Food(&#39;feta&#39;,&nbsp;5);</span></span></span></div><div class="line"><a name="line212"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;fun&nbsp;=&nbsp;new&nbsp;Toy(&#39;robot&#39;,&nbsp;40);</span></span></span></div><div class="line"><a name="line213"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line214"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;In&nbsp;this&nbsp;purely&nbsp;constructed&nbsp;example,&nbsp;we&nbsp;create&nbsp;anonymous&nbsp;function&nbsp;and&nbsp;use&nbsp;`call`&nbsp;to&nbsp;invoke&nbsp;it&nbsp;on</span></span></span></div><div class="line"><a name="line215"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;every&nbsp;object&nbsp;in&nbsp;an&nbsp;array.&nbsp;The&nbsp;main&nbsp;purpose&nbsp;of&nbsp;the&nbsp;anonymous&nbsp;function&nbsp;here&nbsp;is&nbsp;to&nbsp;add&nbsp;a&nbsp;print</span></span></span></div><div class="line"><a name="line216"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;function&nbsp;to&nbsp;every&nbsp;object,&nbsp;which&nbsp;is&nbsp;able&nbsp;to&nbsp;print&nbsp;the&nbsp;right&nbsp;index&nbsp;of&nbsp;the&nbsp;object&nbsp;in&nbsp;the&nbsp;array.</span></span></span></div><div class="line"><a name="line217"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Passing&nbsp;the&nbsp;object&nbsp;as&nbsp;`this`&nbsp;value&nbsp;was&nbsp;not&nbsp;strictly&nbsp;necessary,&nbsp;but&nbsp;is&nbsp;done&nbsp;for&nbsp;explanatory&nbsp;purpose.</span></span></span></div><div class="line"><a name="line218"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line219"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;animals&nbsp;=&nbsp;[</span></span></span></div><div class="line"><a name="line220"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{species:&nbsp;&#39;Lion&#39;,&nbsp;name:&nbsp;&#39;King&#39;},</span></span></span></div><div class="line"><a name="line221"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{species:&nbsp;&#39;Whale&#39;,&nbsp;name:&nbsp;&#39;Fail&#39;}</span></span></span></div><div class="line"><a name="line222"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;];</span></span></span></div><div class="line"><a name="line223"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line224"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;animals.length;&nbsp;i++)&nbsp;{</span></span></span></div><div class="line"><a name="line225"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(function&nbsp;(i)&nbsp;{</span></span></span></div><div class="line"><a name="line226"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.print&nbsp;=&nbsp;function&nbsp;()&nbsp;{</span></span></span></div><div class="line"><a name="line227"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(&#39;#&#39;&nbsp;+&nbsp;i&nbsp;&nbsp;+&nbsp;&#39;&nbsp;&#39;&nbsp;+&nbsp;this.species&nbsp;+&nbsp;&#39;:&nbsp;&#39;&nbsp;+&nbsp;this.name);</span></span></span></div><div class="line"><a name="line228"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line229"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}).call(animals[i],&nbsp;i);</span></span></span></div><div class="line"><a name="line230"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line231"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line232"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Object}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>thisArg</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>The&nbsp;value&nbsp;of&nbsp;this&nbsp;provided&nbsp;for&nbsp;the&nbsp;call&nbsp;to&nbsp;`fun`.Note&nbsp;that&nbsp;this&nbsp;may&nbsp;not&nbsp;be</span></span></span></span></span></div><div class="line"><a name="line233"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;actual&nbsp;value&nbsp;seen&nbsp;by&nbsp;the&nbsp;method:&nbsp;if&nbsp;the&nbsp;method&nbsp;is&nbsp;a&nbsp;function&nbsp;in&nbsp;non-strict&nbsp;mode&nbsp;code,&nbsp;`null`</span></span></span></div><div class="line"><a name="line234"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;and&nbsp;`undefined`&nbsp;will&nbsp;be&nbsp;replaced&nbsp;with&nbsp;the&nbsp;global&nbsp;object,&nbsp;and&nbsp;primitive&nbsp;values&nbsp;will&nbsp;be&nbsp;boxed.</span></span></span></div><div class="line"><a name="line235"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;{Object...}&nbsp;args&nbsp;Arguments&nbsp;for&nbsp;the&nbsp;object.</span></span></span></div><div class="line"><a name="line236"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@return</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Object}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>Returns</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>what&nbsp;the&nbsp;function&nbsp;returns.</span></span></span></span></span></div><div class="line"><a name="line237"><span class="source js"><span class="comment block documentation js"><span>&nbsp;</span><span class="punctuation definition comment js"><span>*/</span></span></span></span></div><div class="line"><a name="line238"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line239"><span class="source js"><span class="comment block documentation js"><span class="punctuation definition comment js"><span>/**</span></span></span></span></div><div class="line"><a name="line240"><a name="Function-method-toString"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@method</span></span><span>&nbsp;toString</span></span></span></div><div class="line"><a name="line241"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Returns&nbsp;a&nbsp;string&nbsp;representing&nbsp;the&nbsp;source&nbsp;code&nbsp;of&nbsp;the&nbsp;function.&nbsp;Overrides&nbsp;the</span></span></span></div><div class="line"><a name="line242"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;`Object.toString`&nbsp;method.</span></span></span></div><div class="line"><a name="line243"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line244"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;The&nbsp;{@link&nbsp;Function}&nbsp;object&nbsp;overrides&nbsp;the&nbsp;`toString`&nbsp;method&nbsp;of&nbsp;the&nbsp;Object&nbsp;object;&nbsp;it&nbsp;does</span></span></span></div><div class="line"><a name="line245"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;not&nbsp;inherit&nbsp;Object.toString.&nbsp;For&nbsp;`Function`&nbsp;objects,&nbsp;the&nbsp;`toString`&nbsp;method&nbsp;returns&nbsp;a&nbsp;string</span></span></span></div><div class="line"><a name="line246"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;representation&nbsp;of&nbsp;the&nbsp;object.</span></span></span></div><div class="line"><a name="line247"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line248"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;JavaScript&nbsp;calls&nbsp;the&nbsp;`toString`&nbsp;method&nbsp;automatically&nbsp;when&nbsp;a&nbsp;`Function`&nbsp;is&nbsp;to&nbsp;be&nbsp;represented&nbsp;as&nbsp;a</span></span></span></div><div class="line"><a name="line249"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;text&nbsp;value&nbsp;or&nbsp;when&nbsp;a&nbsp;Function&nbsp;is&nbsp;referred&nbsp;to&nbsp;in&nbsp;a&nbsp;string&nbsp;concatenation.</span></span></span></div><div class="line"><a name="line250"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line251"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;For&nbsp;`Function`&nbsp;objects,&nbsp;the&nbsp;built-in&nbsp;`toString`&nbsp;method&nbsp;decompiles&nbsp;the&nbsp;function&nbsp;back&nbsp;into&nbsp;the</span></span></span></div><div class="line"><a name="line252"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;JavaScript&nbsp;source&nbsp;that&nbsp;defines&nbsp;the&nbsp;function.&nbsp;This&nbsp;string&nbsp;includes&nbsp;the&nbsp;`function`&nbsp;keyword,&nbsp;the</span></span></span></div><div class="line"><a name="line253"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;argument&nbsp;list,&nbsp;curly&nbsp;braces,&nbsp;and&nbsp;function&nbsp;body.</span></span></span></div><div class="line"><a name="line254"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line255"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@return</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{String}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>The</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>function&nbsp;as&nbsp;a&nbsp;string.</span></span></span></span></span></div><div class="line"><a name="line256"><span class="source js"><span class="comment block documentation js"><span>&nbsp;</span><span class="punctuation definition comment js"><span>*/</span></span></span></span></div><div class="line"><a name="line257"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line258"><span class="source js"><span class="comment line double-slash js"><span class="punctuation definition comment js"><span>//</span></span><span>&nbsp;ECMAScript&nbsp;5&nbsp;methods</span><span>&nbsp;</span></span></span></div><div class="line"><a name="line259"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><a name="line260"><span class="source js"><span class="comment block documentation js"><span class="punctuation definition comment js"><span>/**</span></span></span></span></div><div class="line"><a name="line261"><a name="Function-method-bind"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@method</span></span><span>&nbsp;bind</span></span></span></div><div class="line"><a name="line262"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line263"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;Creates&nbsp;a&nbsp;new&nbsp;function&nbsp;that,&nbsp;when&nbsp;called,&nbsp;has&nbsp;its&nbsp;`this`&nbsp;keyword&nbsp;set</span></span></span></div><div class="line"><a name="line264"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;to&nbsp;the&nbsp;provided&nbsp;value,&nbsp;with&nbsp;a&nbsp;given&nbsp;sequence&nbsp;of&nbsp;arguments&nbsp;preceding</span></span></span></div><div class="line"><a name="line265"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;any&nbsp;provided&nbsp;when&nbsp;the&nbsp;new&nbsp;function&nbsp;was&nbsp;called.</span></span></span></div><div class="line"><a name="line266"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line267"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;The&nbsp;`bind()`&nbsp;function&nbsp;creates&nbsp;a&nbsp;new&nbsp;function&nbsp;(a&nbsp;bound&nbsp;function)&nbsp;with</span></span></span></div><div class="line"><a name="line268"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;same&nbsp;function&nbsp;body&nbsp;(internal&nbsp;Call&nbsp;attribute&nbsp;in&nbsp;ECMAScript&nbsp;5</span></span></span></div><div class="line"><a name="line269"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;terms)&nbsp;as&nbsp;the&nbsp;function&nbsp;it&nbsp;is&nbsp;being&nbsp;called&nbsp;on&nbsp;(the&nbsp;bound&nbsp;function&#39;s</span></span></span></div><div class="line"><a name="line270"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;target&nbsp;function)&nbsp;with&nbsp;the&nbsp;`this`&nbsp;value&nbsp;bound&nbsp;to&nbsp;the&nbsp;first&nbsp;argument&nbsp;of</span></span></span></div><div class="line"><a name="line271"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;`bind()`,&nbsp;which&nbsp;cannot&nbsp;be&nbsp;overridden.&nbsp;`bind()`&nbsp;also&nbsp;accepts&nbsp;leading</span></span></span></div><div class="line"><a name="line272"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;default&nbsp;arguments&nbsp;to&nbsp;provide&nbsp;to&nbsp;the&nbsp;target&nbsp;function&nbsp;when&nbsp;the&nbsp;bound</span></span></span></div><div class="line"><a name="line273"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;function&nbsp;is&nbsp;called.&nbsp;A&nbsp;bound&nbsp;function&nbsp;may&nbsp;also&nbsp;be&nbsp;constructed&nbsp;using</span></span></span></div><div class="line"><a name="line274"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;new&nbsp;operator:&nbsp;doing&nbsp;so&nbsp;acts&nbsp;as&nbsp;though&nbsp;the&nbsp;target&nbsp;function&nbsp;had</span></span></span></div><div class="line"><a name="line275"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;instead&nbsp;been&nbsp;constructed.&nbsp;The&nbsp;provided&nbsp;`this`&nbsp;value&nbsp;is&nbsp;ignored,&nbsp;while</span></span></span></div><div class="line"><a name="line276"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;prepended&nbsp;arguments&nbsp;are&nbsp;provided&nbsp;to&nbsp;the&nbsp;emulated&nbsp;function.</span></span></span></div><div class="line"><a name="line277"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line278"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;##&nbsp;Creating&nbsp;a&nbsp;bound&nbsp;function</span></span></span></div><div class="line"><a name="line279"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line280"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;The&nbsp;simplest&nbsp;use&nbsp;of&nbsp;`bind()`&nbsp;is&nbsp;to&nbsp;make&nbsp;a&nbsp;function&nbsp;that,&nbsp;no&nbsp;matter</span></span></span></div><div class="line"><a name="line281"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;how&nbsp;it&nbsp;is&nbsp;called,&nbsp;is&nbsp;called&nbsp;with&nbsp;a&nbsp;particular&nbsp;`this`&nbsp;value.&nbsp;A&nbsp;common</span></span></span></div><div class="line"><a name="line282"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;mistake&nbsp;for&nbsp;new&nbsp;JavaScript&nbsp;programmers&nbsp;is&nbsp;to&nbsp;extract&nbsp;a&nbsp;method&nbsp;from</span></span></span></div><div class="line"><a name="line283"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;an&nbsp;object,&nbsp;then&nbsp;to&nbsp;later&nbsp;call&nbsp;that&nbsp;function&nbsp;and&nbsp;expect&nbsp;it&nbsp;to&nbsp;use</span></span></span></div><div class="line"><a name="line284"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;original&nbsp;object&nbsp;as&nbsp;its&nbsp;`this`&nbsp;(e.g.&nbsp;by&nbsp;using&nbsp;that&nbsp;method&nbsp;in</span></span></span></div><div class="line"><a name="line285"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;callback-based&nbsp;code).&nbsp;Without&nbsp;special&nbsp;care,&nbsp;however,&nbsp;the&nbsp;original</span></span></span></div><div class="line"><a name="line286"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;object&nbsp;is&nbsp;usually&nbsp;lost.&nbsp;Creating&nbsp;a&nbsp;bound&nbsp;function&nbsp;from&nbsp;the</span></span></span></div><div class="line"><a name="line287"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;function,&nbsp;using&nbsp;the&nbsp;original&nbsp;object,&nbsp;neatly&nbsp;solves&nbsp;`this`&nbsp;problem:</span></span></span></div><div class="line"><a name="line288"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line289"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;x&nbsp;=&nbsp;9;</span></span></span></div><div class="line"><a name="line290"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;module&nbsp;=&nbsp;{</span></span></span></div><div class="line"><a name="line291"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x:&nbsp;81,</span></span></span></div><div class="line"><a name="line292"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getX:&nbsp;function()&nbsp;{&nbsp;return&nbsp;this.x;&nbsp;}</span></span></span></div><div class="line"><a name="line293"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};</span></span></span></div><div class="line"><a name="line294"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line295"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module.getX();&nbsp;//&nbsp;81</span></span></span></div><div class="line"><a name="line296"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line297"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;getX&nbsp;=&nbsp;module.getX;</span></span></span></div><div class="line"><a name="line298"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getX();&nbsp;//&nbsp;9,&nbsp;because&nbsp;in&nbsp;this&nbsp;case,&nbsp;&quot;this&quot;&nbsp;refers&nbsp;to&nbsp;the&nbsp;global&nbsp;object</span></span></span></div><div class="line"><a name="line299"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line300"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;create&nbsp;a&nbsp;new&nbsp;function&nbsp;with&nbsp;&#39;this&#39;&nbsp;bound&nbsp;to&nbsp;module</span></span></span></div><div class="line"><a name="line301"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;boundGetX&nbsp;=&nbsp;getX.bind(module);</span></span></span></div><div class="line"><a name="line302"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;boundGetX();&nbsp;//&nbsp;81</span></span></span></div><div class="line"><a name="line303"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line304"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;##&nbsp;Partial&nbsp;functions</span></span></span></div><div class="line"><a name="line305"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line306"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;The&nbsp;next&nbsp;simplest&nbsp;use&nbsp;of&nbsp;`bind()`&nbsp;is&nbsp;to&nbsp;make&nbsp;a&nbsp;function&nbsp;with</span></span></span></div><div class="line"><a name="line307"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;pre-specified&nbsp;initial&nbsp;arguments.&nbsp;These&nbsp;arguments&nbsp;(if&nbsp;any)&nbsp;follow</span></span></span></div><div class="line"><a name="line308"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;the&nbsp;provided&nbsp;this&nbsp;value&nbsp;and&nbsp;are&nbsp;then&nbsp;inserted&nbsp;at&nbsp;the&nbsp;start&nbsp;of&nbsp;the</span></span></span></div><div class="line"><a name="line309"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;arguments&nbsp;passed&nbsp;to&nbsp;the&nbsp;target&nbsp;function,&nbsp;followed&nbsp;by&nbsp;the&nbsp;arguments</span></span></span></div><div class="line"><a name="line310"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;passed&nbsp;to&nbsp;the&nbsp;bound&nbsp;function,&nbsp;whenever&nbsp;the&nbsp;bound&nbsp;function&nbsp;is</span></span></span></div><div class="line"><a name="line311"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;called.</span></span></span></div><div class="line"><a name="line312"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line313"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;list()&nbsp;{</span></span></span></div><div class="line"><a name="line314"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;Array.prototype.slice.call(arguments);</span></span></span></div><div class="line"><a name="line315"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></div><div class="line"><a name="line316"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line317"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;list1&nbsp;=&nbsp;list(1,&nbsp;2,&nbsp;3);&nbsp;//&nbsp;[1,&nbsp;2,&nbsp;3]</span></span></span></div><div class="line"><a name="line318"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line319"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;Create&nbsp;a&nbsp;function&nbsp;with&nbsp;a&nbsp;preset&nbsp;leading&nbsp;argument</span></span></span></div><div class="line"><a name="line320"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;leadingZeroList&nbsp;=&nbsp;list.bind(undefined,&nbsp;37);</span></span></span></div><div class="line"><a name="line321"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line322"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;list2&nbsp;=&nbsp;leadingZeroList();&nbsp;//&nbsp;[37]</span></span></span></div><div class="line"><a name="line323"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;list3&nbsp;=&nbsp;leadingZeroList(1,&nbsp;2,&nbsp;3);&nbsp;//&nbsp;[37,&nbsp;1,&nbsp;2,&nbsp;3]</span></span></span></div><div class="line"><a name="line324"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line325"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;**NOTE:**&nbsp;This&nbsp;method&nbsp;is&nbsp;part&nbsp;of&nbsp;the&nbsp;ECMAScript&nbsp;5&nbsp;standard.</span></span></span></div><div class="line"><a name="line326"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line327"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Object}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>thisArg</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>The&nbsp;value&nbsp;to&nbsp;be&nbsp;passed&nbsp;as&nbsp;the&nbsp;`this`</span></span></span></span></span></div><div class="line"><a name="line328"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;parameter&nbsp;to&nbsp;the&nbsp;target&nbsp;function&nbsp;when&nbsp;the&nbsp;bound&nbsp;function&nbsp;is</span></span></span></div><div class="line"><a name="line329"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;called.&nbsp;The&nbsp;value&nbsp;is&nbsp;ignored&nbsp;if&nbsp;the&nbsp;bound&nbsp;function&nbsp;is&nbsp;constructed</span></span></span></div><div class="line"><a name="line330"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;using&nbsp;the&nbsp;new&nbsp;operator.</span></span></span></div><div class="line"><a name="line331"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line332"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@param</span></span><span>&nbsp;{Mixed...}&nbsp;[args]&nbsp;Arguments&nbsp;to&nbsp;prepend&nbsp;to&nbsp;arguments&nbsp;provided</span></span></span></div><div class="line"><a name="line333"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;to&nbsp;the&nbsp;bound&nbsp;function&nbsp;when&nbsp;invoking&nbsp;the&nbsp;target&nbsp;function.</span></span></span></div><div class="line"><a name="line334"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*</span></span></span></div><div class="line"><a name="line335"><span class="source js"><span class="comment block documentation js"><span>&nbsp;*&nbsp;</span><span class="storage type class jsdoc"><span>@return</span></span><span>&nbsp;</span><span class="other meta jsdoc"><span class="entity name type instance jsdoc"><span>{Function}</span></span><span>&nbsp;</span><span class="variable other jsdoc"><span>The</span></span><span>&nbsp;</span><span class="other description jsdoc"><span>bound&nbsp;function.</span></span></span></span></span></div><div class="line"><a name="line336"><span class="source js"><span class="comment block documentation js"><span>&nbsp;</span><span class="punctuation definition comment js"><span>*/</span></span></span></span></div></pre>
</body>
<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-1396058-28', 'auto');
    ga('send', 'pageview');

</script>
</html>
